package com.eliza.demo.db.fg

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.eliza.demo.R
import com.eliza.demo.db.activity.ContactorAdapter
import com.eliza.demo.qq.activity.QQAdapter
import com.eliza.demo.vm.ContactorDbVm
import com.eliza.library.model.Contactor

class InfoShowFragment : Fragment() {
    lateinit var contactorAdapter: ContactorAdapter

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        var view = inflater.inflate(R.layout.fragment_contactor_show, container, false)

        parentFragment?.context.let {
            val recycleView = view.findViewById<RecyclerView>(R.id.Contactor_recycle)
            recycleView.layoutManager = LinearLayoutManager(context)
            contactorAdapter = com.eliza.demo.db.activity.ContactorAdapter(
                listOf<Contactor>(Contactor("name", 12))
            )
            recycleView.adapter = contactorAdapter
        }
        return view
    }

    fun setAllContactorsLive(cdv: ContactorDbVm) {
        cdv.getAllContactorsLive().observe(this) {
            contactorAdapter.conList = it
            contactorAdapter.notifyDataSetChanged()
        }
    }
}